// const process=require('process')
const cp = require('child_process')
let spl1 = cp.spawn('node', ['test1.js', 'one', 'two', 'three', 'four'], {
  cwd: 'test',
  stdio:['ipc','pipe','ignore']
})
let spl2 = cp.spawn('node', ['test2.js'], {
  stdio: 'pipe'
})
spl1.stdout.on('data', function (data) {
  console.log('child process 1 out :', data.toString());
  spl2.stdin.write(data)
  spl1.kill('SIGTERM')  //强制关闭子进程
})
spl1.on('exit', function (code, sign) {
  console.log(code, sign);
  if (!code) {
    console.log('child process 1 exit errExit code is ', sign);
  } else {
    console.log('child process 1 exit exit code is ', code);
  }
  process.exit()
})
spl1.on('error', function (err) {
  console.log('child process: ' + err);
  process.exit()
})
spl1.on('disconnect',()=>{
  console.log('spl1 ipc closed');
})